--[[	$Id: dbm.lua 2358 2011-12-05 14:54:45Z sdkyron@gmail.com $	]]

if not IsAddOnLoaded("DBM-Core") then return end

local _, caelCore = ...

caelCore.dbm = caelCore.createModule("Deadly Boss Mods")

local SkinBars = function(self)
	for bar in self:GetBarIterator() do
		if not bar.injected then
			bar.ApplyStyle = function()
				local frame		=	bar.frame
				local tbar		=	_G[frame:GetName().."Bar"]
				local spark		=	_G[frame:GetName().."BarSpark"]
				local texture	=	_G[frame:GetName().."BarTexture"]
				local icon1		=	_G[frame:GetName().."BarIcon1"]
				local icon2		=	_G[frame:GetName().."BarIcon2"]
				local name		=	_G[frame:GetName().."BarName"]
				local timer		=	_G[frame:GetName().."BarTimer"]

				if icon1 then
					icon1:SetSize(14, 14)
					icon1:SetPoint("RIGHT", frame, "LEFT", -5, 0)
				end

				if icon2 then
					icon2:SetSize(14, 14)
				end

				if not frame.styled then
					frame:SetScale(1)
					frame:SetHeight(14)
					frame.background = caelMedia.createBackdrop(frame)
					frame.styled = true
				end

				if not tbar.styled then
					tbar:SetAllPoints(frame)
					frame.styled = true
				end

				if not spark.killed then
					spark:SetAlpha(0)
					spark:SetTexture(nil)
					spark.killed = true
				end

				if not icon1.styled then
					icon1:SetTexCoord(0.07, 0.93, 0.07, 0.93)
					icon1.frame = CreateFrame("Frame", nil, tbar)
					icon1.frame:SetFrameStrata("BACKGROUND")
					icon1.frame:SetAllPoints(icon1)
					icon1.frame.background = caelMedia.createBackdrop(icon1.frame)
					icon1.styled = true
				end

				if not texture.styled then
					texture:SetTexture(caelMedia.files.statusBarC)
					texture.styled = true
				end

				if not name.styled then
					name:SetFont(caelMedia.fonts.NORMAL, 9)
					name:SetShadowOffset(0.75, -0.75)
					name.SetFont = function() end
					name.styled = true
				end

				if not timer.styled then	
					timer:SetFont(caelMedia.fonts.CUSTOM_NUMBERFONT, 9)
					timer:SetShadowOffset(0.75, -0.75)
					timer.SetFont = function() end
					timer.styled = true
				end

				frame:Show()
				bar:Update(0)
				bar.injected = true
			end
			bar:ApplyStyle()
		end
	end
end

local SetupDBM = function()
	DBM_SavedOptions.Enabled = true
	DBM_SavedOptions.ShowMinimapButton = false
	DBM_SavedOptions.ShowSpecialWarnings = true
	DBM_SavedOptions.SpecialWarningPoint = "CENTER"
	DBM_SavedOptions.SpecialWarningX = 0
	DBM_SavedOptions.SpecialWarningY = 200
	DBM_SavedOptions.SpecialWarningFont = caelMedia.fonts.NORMAL
	DBM_SavedOptions.SpecialWarningFontColor = {0.69, 0.31, 0.31}
	DBM_SavedOptions.SpecialWarningFontSize = 15
	DBM_SavedOptions.WarningIconLeft = false
	DBM_SavedOptions.WarningIconRight = false
	DBM_SavedOptions.AlwaysShowHealthFrame = false
	DBM_SavedOptions.ShowSpecialWarnings = true
	DBM_SavedOptions.ShowFakedRaidWarnings = true
	DBM_SavedOptions.DontShowBossAnnounces = true
	DBM_SavedOptions.AlwaysShowSpeedKillTimer = false
	DBM_SavedOptions.LatencyThreshold = 50
	DBM_SavedOptions.InfoFramePoint = "TOP"
	DBM_SavedOptions.InfoFrameX = 315
	DBM_SavedOptions.InfoFrameY = -5
	DBM_SavedOptions.InfoFrameLocked = true
	DBM_SavedOptions.RangeFramePoint = "TOP"
	DBM_SavedOptions.RangeFrameX = -315
	DBM_SavedOptions.RangeFrameY = -5
	DBM_SavedOptions.RangeFrameLocked = true

	DBT_SavedOptions["DBM"].Scale = 1
	DBT_SavedOptions["DBM"].HugeScale = 1
	DBT_SavedOptions["DBM"].BarXOffset = 0
	DBT_SavedOptions["DBM"].BarYOffset = 5
	DBT_SavedOptions["DBM"].HugeBarXOffset = 0
	DBT_SavedOptions["DBM"].HugeBarYOffset = 5
	DBT_SavedOptions["DBM"].Font = caelMedia.fonts.NORMAL
	DBT_SavedOptions["DBM"].FontSize = 9
	DBT_SavedOptions["DBM"].Width = 145
	DBT_SavedOptions["DBM"].HugeWidth = 145
	DBT_SavedOptions["DBM"].TimerX = 95
	DBT_SavedOptions["DBM"].TimerY = 12.5
	DBT_SavedOptions["DBM"].TimerPoint = "LEFT"
	DBT_SavedOptions["DBM"].FillUpBars = true
	DBT_SavedOptions["DBM"].IconLeft = true
	DBT_SavedOptions["DBM"].ExpandUpwards = false
	DBT_SavedOptions["DBM"].Texture = caelMedia.files.statusBarC
	DBT_SavedOptions["DBM"].IconRight = false
	DBT_SavedOptions["DBM"].HugeBarsEnabled = true
end

hooksecurefunc(DBT, "CreateBar", SkinBars)
--[[
DBM.InfoFrame:Show()
DBM.InfoFrame:Hide()

DBMInfoFrame:HookScript("OnShow", function(self)
	self:SetBackdrop(nil)
	caelMedia.createBackdrop(self)
end)
--]]
DBM.RangeCheck:Show()
DBM.RangeCheck:Hide()

DBMRangeCheck:HookScript("OnShow", function(self)
	self:SetBackdrop(nil)
	caelMedia.createBackdrop(self)
end)

caelCore.dbm:RegisterEvent("PLAYER_LOGIN")
caelCore.dbm:SetScript("OnEvent", function(self, event)
	SetupDBM()
end)

